<div class="row">
<style>
img{width:50px;border:none;}
.my_red{color:red;}
.my_green{color:green;}
</style>
<!-- 表示一个成功的或积极的动作 -->
<a href="{:U('News/index')}"><button type="button" class="btn btn-primary">资讯列表</button></a>
<a href="javascript:void(0)"><button type="button" class="btn btn-primary  active">分类列表</button></a>
<a href="{:U('News/news')}"><button type="button" class="btn btn-primary">添加资讯</button></a>
<table class="table table-hover table-responsive">
   <thead>
      <tr>
         <th>分类名称</th>
         <th>资讯数量</th>
         <th>管理操作</th>
      </tr>
   </thead>
   <tbody>
   <volist name="data" id="data">
      <tr id="tr_{$data.id}">
         <td id="td_{$data.id}">{$data.name}</td>
         <td>{$data.count}</td>
         <td>
		         <a href="{:U('News/delete_type')}?id={$data.id}" class="delete_type">删除 </a>  
		         <a href="#" class="edit" data-id="{$data.id}" data-toggle="modal" 
   data-target="#myModaledit">修改</a>
          </td>
      </tr>
    </volist>  
   </tbody>
</table>
<button class="btn btn-primary" data-toggle="modal" 
   data-target="#myModal">新增分类</button>
{$page}


<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" 
   aria-labelledby="myModalLabel" aria-hidden="true">
   <div class="modal-dialog">
      <div class="modal-content">
         <div class="modal-body">
		   <form role="form" method="post" id="type_form" action="{:U('News/addtype')}">
		   <div class="form-group">
		      <label for="content">分类名称</label>
		      <input type="text" name="content" class="form-control" id="content" 
		         placeholder="请输入分类名称">
		      <span class="help-block">支持分类批量添加，多个分类请以英文逗号分隔</span>
		   </div>
		  
		</form>
         </div>
         <div class="modal-footer">
            <button type="button" class="btn btn-default" 
               data-dismiss="modal">关闭
            </button>
            <button type="button" class="btn btn-primary" id="addtype">添加</button>
         </div>
      </div><!-- /.modal-content -->
</div><!-- /.modal -->
</div>

<!-- 模态框（Modal）编辑分类 -->
<div class="modal fade" id="myModaledit" tabindex="-1" role="dialog" 
   aria-labelledby="myModaleditLabel" aria-hidden="true">
   <div class="modal-dialog">
      <div class="modal-content">
         <div class="modal-body">
	          <div class="form-group">
			      <label for="content">分类名称</label>
			      <input type="text" name="content" class="form-control" id="edit_name" 
			         placeholder="请输入分类名称">
				  <input type="hidden" id="edit_id" value=""/>
			   </div>
		  	
         </div>
         <div class="modal-footer">
            <button type="button" class="btn btn-default" 
               data-dismiss="modal">关闭
            </button>
            <button type="button" class="btn btn-primary" id="edit_type">修改</button>
         </div>
      </div><!-- /.modal-content -->
</div><!-- /.modal -->
</div>


</div>
<script>
   $(function () { $("[data-toggle='tooltip']").tooltip(); });
   $(document).ready(function(){
	   $("#collect").click(function(){
		   $("#collect_form").submit();
	   });
	   $("#addtype").click(function(){
		   $("#type_form").submit();
	   });
	   $('.delete_type').click(function(){
		   if(!confirm('您确定要删除该分类吗？删除该分类之后，该分类下的资讯也将同时被删除。')) return false;
	   });
	   $('.edit').click(function(){
		   var id=$(this).attr('data-id');
		   var name=$('#td_'+id).text();
		   $('#edit_name').val(name);
		   $('#edit_id').val(id);
	   });
	   $("#edit_type").click(function(){
		   $.get("{:U('News/modtype')}",{id:$('#edit_id').val(),name:$('#edit_name').val()},function(data){
			   if(data==1){
				   alert('恭喜您，修改成功！');
				   location.reload();
			   }else{
				   alert('修改失败！可能是您对该分类未做修改或者数据库中存在相同分类。');
			   }
		   });
	   });
	   
   });
</script>








